package com.yuanheng100.ems4j.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by jlqian on 2017/1/13.
 */
public class Ems4jMenuSQLProvider
{
    public String selectMenuListByAppIdAndRoleId(@Param("appId") final int appId, @Param("roleId") final int roleId)
    {
        return new SQL()
        {{
            SELECT("m.menuid, m.appid, m.parentid, m.menuname, m.url, m.ordernum, m.permission, m.description, m.menutype");
            FROM("ems4j_menu m");
            LEFT_OUTER_JOIN("ems4j_role_menu rm ON rm.menuId = m.menuId");
            WHERE("m.appId = #{appId,jdbcType=INTEGER}");
            if (roleId != 0)
            {
                WHERE("rm.roleId = #{roleId,jdbcType=INTEGER}");
            }
        }}.toString();
    }
}
